package com.problemproject.dome;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.problemproject.dome.Utils.DisplayUtil;
import com.problemproject.dome.base.BaseActivity;
import com.problemproject.dome.common.App;
import com.problemproject.dome.common.SPNoCleanUtil;
import com.problemproject.dome.encryption.DataEncryptionActivity;
import com.problemproject.dome.gridView.GridViewActivity;
import com.problemproject.dome.recyclerview.RecyclerViewActivity;
import com.problemproject.dome.search.SearchHistoryActivity;
import com.problemproject.dome.viewpager.ViewPagerFragmentActivity;

public class MainActivity extends BaseActivity implements View.OnClickListener {
    private CardView mainGridView;
    private CardView tabFragment;
    private CardView RecyclerView;
    private CardView SearchHistory;
    private CardView thirdParty;
    private CardView dataEncryption;


    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mainGridView = (CardView) findViewById(R.id.main_gridView);
        mainGridView.setOnClickListener(this);

        tabFragment = (CardView) findViewById(R.id.tab_fragment);
        tabFragment.setOnClickListener(this);

        RecyclerView = (CardView) findViewById(R.id.RecyclerView);
        RecyclerView.setOnClickListener(this);

        SearchHistory = (CardView) findViewById(R.id.Search_history);
        SearchHistory.setOnClickListener(this);

        thirdParty = (CardView) findViewById(R.id.third_party);
        thirdParty.setOnClickListener(this);

        dataEncryption = (CardView) findViewById(R.id.data_encryption);
        dataEncryption.setOnClickListener(this);

        WindowManager manager = this.getWindowManager();
        DisplayMetrics outMetrics = new DisplayMetrics();
        manager.getDefaultDisplay().getMetrics(outMetrics);
        int width = outMetrics.widthPixels;
        int height = outMetrics.heightPixels;
        Log.e("px==dp", "高度=" + height + ",宽度=" + width);

        int i = DisplayUtil.px2dip(MainActivity.this, height);
        int i1 = DisplayUtil.px2dip(MainActivity.this, width);
        Log.e("px==dp", "高度1920px=" + i + ",宽度1080px=" + i1);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.main_gridView:
                startActivity(new Intent(MainActivity.this, GridViewActivity.class));
                break;
            case R.id.tab_fragment:
                startActivity(new Intent(MainActivity.this, ViewPagerFragmentActivity.class));
                break;
            case R.id.RecyclerView:
                startActivity(new Intent(MainActivity.this, RecyclerViewActivity.class));
                break;
            case R.id.Search_history:
                startActivity(new Intent(MainActivity.this, SearchHistoryActivity.class));
                break;
            case R.id.third_party:
                final AlertDialog.Builder alterDiaglog = new AlertDialog.Builder(MainActivity.this);
                alterDiaglog.setIcon(R.mipmap.ic_launcher);//图标
                alterDiaglog.setTitle("隐私协议");//文字
                alterDiaglog.setMessage("同意后初始化第三方sdk");//提示消息
                //积极的选择
                alterDiaglog.setPositiveButton("同意", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        next();
                    }
                });
                //消极的选择
                alterDiaglog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                break;
            case R.id.data_encryption:
                 startActivity(new Intent(MainActivity.this, DataEncryptionActivity.class));
                break;
        }
    }

    private void next() {

        ((App) getApplication().getApplicationContext()).initSDK();

    }
}